<template>
    <div>
       <h1>房号添加</h1>
       <table class="table table-bordered">
        <tbody>
            <tr>
                <td align="right">房型名称</td>
                <td>
                    <select v-model="query.typeName">
                        <option value="">请选择</option>
                        <option :value="item.typeName" v-for="item in gethouse">{{ item.typeName }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">房间号码</td>
                <td>
                    <input type="text" v-model="query.number"/>
                </td>
            </tr>
            <tr>
                <td align="right">房号描述</td>
                <td>
                    <textarea v-model="query.desc"></textarea>
                </td>
            </tr>
            <tr>
                <td align="right">状态</td>
                <td>
                    <input type="radio" name="stateq" value="上架" v-model="query.state"/>上架
                    <input type="radio" name="stateq" value="下架" v-model="query.state"/>下架
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="添加" class="btn btn-success" @click="ok"/>
                </td>
            </tr>
        </tbody>
       </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,reactive,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();

let query:any=reactive
({
  "typeName": "",
  "number": "",
  "desc": "",
  "state": "上架"
})

let gethouse:any=ref([])

onMounted(()=>{
    showhouse();
})

const showhouse=()=>
{
    axios
    ({
        url:'/api/House/GetHouse',
        method:'get',
    })
    .then(res=>{
        console.log(res);
        gethouse.value=res.data;
    })
    .catch(err=>{

    })
}


const ok=()=>
{
    if(query.typeName=="")
    {
        alert("房型名称不能为空");
        return;
    }
    axios
    ({
        url:'/api/House/NumberAdd',
        method:'post',
        data:query
    })
    .then(res=>{
        if(res.data==-1)
        {
            alert("房间号重复");
            return;
        }
        if(res.data>0)
        {
          alert("添加成功");
          router.push('houseNumberList');
          return;
        }
        else
        {
            alert("添加失败");
            return;
        }
    })
    .catch(err=>{

    })
}



</script>

<style scoped>

</style>